package com.vcredit.creditcat.service.speedloan;

import java.io.IOException;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.vcredit.creditcat.model.ProcessSpecial;
import com.vcredit.creditcat.persistence.base.ProcessSpecialMapper;

/**
 * 
 **/
@Service
public class ProcessSpecialService {
	@Autowired
	private ProcessSpecialMapper mapper;

	@CacheEvict(key = "'config:processSpecials'", value = "processSpecial")
	public void insert(ProcessSpecial obj) {
		mapper.insert(obj);
	}

	@CacheEvict(key = "'config:processSpecials'", value = "processSpecial")
	public void update(ProcessSpecial obj) {
		mapper.update(obj);
	}

	@Cacheable(key = "'config:processSpecials'", value = "processSpecial")
	public List<ProcessSpecial> findAll() {
		return mapper.findAll();
	}
	
	public ProcessSpecial findById(long  id) {
		return mapper.findById(id);
	}
	
	
	public List<ProcessSpecial> findAllByVersion(String appDesc,String mobile) throws IOException{
		String version ="default";
		if(StringUtils.isNotBlank(appDesc)) {
			version = appDesc;
		}
		return mapper.findAllByVersion(version,mobile);
	}
	@CacheEvict(value = "processSpecial",key = "'config:processSpecia'",beforeInvocation=true)
	public void clearProcessSpecialsCache() {
		System.out.println("ProcessSpecials");
	}

	private List<ProcessSpecial> find(ProcessSpecial obj) {
		return mapper.find(obj);
	}

	public ProcessSpecial findByProductId(long productId) {
		return mapper.findByProductId(productId);
	}

	public Long findNewFastProduct(String appDesc){
		String version ="default";
		if(StringUtils.isNotBlank(appDesc)) {
			version = appDesc;
		}
		return mapper.findNewFastProduct(version);
	}
}